package guda.house.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.house.biz.BillParkingBiz;
import guda.house.dal.dao.BillParkingDAO;
import guda.house.dal.dataobject.BillParkingDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class BillParkingBizImpl implements BillParkingBiz{

    private final static Logger logger = LoggerFactory.getLogger(BillParkingBizImpl.class);

    @Autowired
    private BillParkingDAO billParkingDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            BillParkingDO billParkingDO = billParkingDAO.getBillParkingById(id);
            bizResult.data.put("billParkingDO", billParkingDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query BillParking error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = billParkingDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<BillParkingDO> billParkingList = billParkingDAO.selectForPage(baseQuery);
            bizResult.data.put("billParkingList", billParkingList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view BillParking list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            billParkingDAO.delBillParkingById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete billParking error", e);
        }
        return bizResult;
    }

    public BizResult create(BillParkingDO billParkingDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = billParkingDAO.insert(billParkingDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create BillParking error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(BillParkingDO billParkingDO) {
        BizResult bizResult = new BizResult();
        try {
            billParkingDAO.updateByIdSelective(billParkingDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update BillParking error", e);
        }
        return bizResult;
    }


}
